
package es.ceu.mp2.conway;
import org.apache.log4j.Logger;

public class ReaderFactory {

    private static final Logger log = Logger.getLogger(TXTReader.class);

    public Reader getReader(String fileName){
        final String extension = getExtension(fileName);

        if (".txt".equals(extension))
            return new TXTReader();

        if (".xml".equals(extension))
            return new XMLReader();

        log.error(" Lector de ficheros '" + extension + "' no soportado.");
        throw new ReaderNotFoundException(" Lector de ficheros '" + extension + "' no soportado.");
    }

    private String getExtension(String fileName) {
        String extension = fileName.substring(fileName.lastIndexOf("."));
        return fileName.substring(fileName.length() - extension.length());
    }

}
